/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MultipleSolutionPanel.java
 *
 * Created on May 24, 2011, 12:03:08 PM
 */

package view;

import java.awt.ComponentOrientation;
import java.util.Vector;

/**
 *
 * @author andre
 */
public class MultipleSolutionPanel extends javax.swing.JPanel {

    private int resourcesNumber;
    private String[] resources;
    private String[] tasks;
    int[][] costMatrix;

    /** Creates new form MultipleSolutionPanel */
    public MultipleSolutionPanel() {
        initComponents();

        clearSolutions();
    }



    /*
     * Adds a solution tab
     */
    public void addSolutionTab(Boolean[][] solutionMatrix)
    {
        /*
         * Testing jTabbedPane addition
         */
        SolutionPanel solutionPanel = new SolutionPanel();;

        if (solutionMatrix != null)
        {
            // TODO: cleaning, the way of handling tasks/resources name is aweful
            solutionPanel.setTasks(tasks);
            // TODO: same uglyness here
            solutionPanel.setCostMatrix(costMatrix);
            solutionPanel.displaySolutionFromBooleanSolutionMatrix(solutionMatrix);
        }
        else
        {
            solutionPanel.initTable(resourcesNumber);
        }
        jTabbedPane1.add("Solution " + (jTabbedPane1.getTabCount()+1),
                solutionPanel);
    }

    public void setResourcesNumber(int resourcesNumber)
    {
        this.resourcesNumber = resourcesNumber;
    }

    public void displaySolutionFromBooleanSolutionMatrices(Vector<Boolean[][]> solutionMatrices)
    {
        /*
         * Remove all the previous solutions before re-setting some more.
         */
        jTabbedPane1.removeAll();
        
        for(int i=0; i<solutionMatrices.size(); i++)
        {
            addSolutionTab(solutionMatrices.get(i));
        }
    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();

        setName("MultipleSolutionPanelForm"); // NOI18N

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables

    public void setResources(String[] resources)
    {
        this.resources = resources;
    }

    public void setTasks(String[] tasks)
    {
        this.tasks = tasks;
    }

    public void setCostMatrix(int[][] costMatrix)
    {
        this.costMatrix = costMatrix;
    }

    /*
     * Remove all the added tabs and leave one with an empty solution
     */
    public final void clearSolutions()
    {
        jTabbedPane1.removeAll();
        addSolutionTab(null);
    }


}
